#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int
main(void)
{
	char msg[] = "this is a txt book";
	
	int fd = open("lseek.txt", O_RDWR | O_CREAT, 0644);
	if(fd < 0){
		perror("open faild");
		exit(1);
	}

	if(write(fd, msg, strlen(msg)) < 0){
		perror("write txt failed");
		exit(1);
	};

	char buffer[1024];
	lseek(fd, 0, SEEK_SET);
	int n = read(fd, buffer, 1);
	while(n){
		if(write(STDOUT_FILENO, buffer, n) < 0){
			perror("write stdout failed");
			exit(1);
		}
		n = read(fd, buffer, 1);		
	}

	return 0;
}